package com.yami.shop.factory;

import com.yami.shop.bean.app.param.CreateOrderRequest;
import com.yami.shop.bean.enums.OrderStatus;
import com.yami.shop.bean.model.Order;
import com.yami.shop.bean.model.UserAddrOrder;
import com.yami.shop.constant.ConstantValue;

import java.util.Date;
import java.util.Objects;

public class OrderFactory {

    public static Order create(CreateOrderRequest dto){

        if(Objects.isNull(dto)){
            return null;
        }
        // 订单信息
        com.yami.shop.bean.model.Order order = new com.yami.shop.bean.model.Order();

        order.setShopId(1L);
        order.setOrderNumber(dto.getOrderId());
        // 订单商品名称
        order.setProdName(null);
        // 用户id
        order.setUserId(dto.getName());
        // 商品总额
        order.setTotal(0d);
        // 实际总额
        order.setActualTotal(0d);
        order.setStatus(OrderStatus.UNPAY.value());
        order.setUpdateTime(new Date());
        order.setCreateTime(new Date());
        order.setIsPayed(0);
        order.setDeleteStatus(0);
        order.setProductNums(0);
        order.setAddrOrderId(null);
        order.setReduceAmount(0d);
        order.setFreightAmount(0d);
        order.setRemarks(null);
        order.setOrderItems(null);
        return order;
    }

    public static UserAddrOrder createAddr(CreateOrderRequest dto){
        UserAddrOrder addr = new UserAddrOrder();
        addr.setReceiver(dto.getName());
        addr.setProvinceId(Long.valueOf(dto.getProvinceId()));
        addr.setCityId(Long.valueOf(dto.getCityId()));
        addr.setAreaId(Long.valueOf(dto.getCountyId()));
        addr.setMobile(dto.getCellphone());
        addr.setAddr(dto.getAddress());
        addr.setUserId(ConstantValue.USER);
        addr.setCreateTime(new Date());
        addr.setAddrId(0L);
        return addr;
    }



}
